﻿#include "T_CreateNewReportWidget.h"
#include <iostream>
#include <QHBoxLayout>
#include <QIcon>
#include <QVBoxLayout>
#include <QLabel>
#include "ElaPushButton.h"
#include "ElaLineEdit.h"
#include "ElaComboBox.h"
#include "ElaScrollPageArea.h"
#include "ElaImageCard.h"
#include "ElaStatusBar.h"
#include "ElaText.h"
#include "GenerateReportBase.h"
#include "MainWindow.h"
#include "BaseModule/GlobalHelper.h"
#include "CreateNewReport.h"
using namespace std;
namespace GenerateReport
{
    T_CreateNewReportWidget::T_CreateNewReportWidget(QWidget* parent)
        : ElaWidget(parent)
    {
        setWindowTitle(QStringLiteral("新建报告"));
        setWindowIcon(QIcon(":/QUI/image/GenerateReport_CreateNewReport1x.png"));
        //setStyleSheet("QWidget { qproperty - windowTitleFontSize: 14px; }");
        this->setIsFixedSize(true);
        setWindowModality(Qt::ApplicationModal);
        setWindowButtonFlags(ElaAppBarType::CloseButtonHint);

        //总布局（纵）
        QVBoxLayout* mainLayout = new QVBoxLayout(this);

        //第一行布局（横）
        QHBoxLayout* firstRowLayout = new QHBoxLayout;
        //第二行布局（横）
        QHBoxLayout* secondRowLayout = new QHBoxLayout;
        //第三行布局（横）
        QHBoxLayout* thirdRowLayout = new QHBoxLayout;

        //第一行内容：报告名称设置
        ElaText* reportNameText = new ElaText(QStringLiteral("报告名称"), this);
        reportNameText->setWordWrap(false);
        reportNameText->setTextPixelSize(14);

        //ElaLineEdit* 
        _nameEdit = new ElaLineEdit(this);
        _nameEdit->setPlaceholderText("请输入");
        _nameEdit->setFixedSize(300, 32);
        _nameEdit->setAlignment(Qt::AlignLeft);
        //_nameEdit->setStyleSheet("QLineEdit::placeholder { color: red; }");//yr-设置未生效
        firstRowLayout->addWidget(reportNameText);
        firstRowLayout->addWidget(_nameEdit);
        firstRowLayout->setAlignment(Qt::AlignLeft);
        firstRowLayout->setSpacing(0);

        //第二行内容：模板调用
        ElaText* templateCallText = new ElaText(QStringLiteral("模板调用"), this);
        templateCallText->setWordWrap(false);
        templateCallText->setTextPixelSize(14);
        ElaComboBox* _templateCallComboBox = new ElaComboBox(this);
        QStringList _templateCallComboList
        {
            "无",
            //"模板1",
        };
        _templateCallComboBox->setFixedWidth(310);
        _templateCallComboBox->addItems(_templateCallComboList);
        secondRowLayout->addWidget(templateCallText);
        secondRowLayout->addWidget(_templateCallComboBox);
        secondRowLayout->setAlignment(Qt::AlignLeft);
        secondRowLayout->setSpacing(2);

        //第三行内容：确定、取消按钮
        ElaPushButton* cancelButton = new ElaPushButton(QStringLiteral("取消"), this);
        cancelButton->setFixedWidth(80);
        ElaPushButton* confirmButton = new ElaPushButton(QStringLiteral("确定"), this);
        confirmButton->setFixedWidth(80);
        thirdRowLayout->addWidget(cancelButton);
        thirdRowLayout->addWidget(confirmButton);
        thirdRowLayout->setAlignment(Qt::AlignRight);
        thirdRowLayout->setSpacing(2);

        //总体布局
        //mainLayout->setContentsMargins(0, 0, 0, 0);
        mainLayout->addLayout(firstRowLayout);
        mainLayout->addLayout(secondRowLayout);
        mainLayout->addLayout(thirdRowLayout);
        //mainLayout->setSpacing(20);

        //接口
        connect(_nameEdit, &ElaLineEdit::textEdited, this, &T_CreateNewReportWidget::slot_onNameEditTextEdit);
        connect(_nameEdit, &ElaLineEdit::focusIn, this, &T_CreateNewReportWidget::slot_onNameEditTextEdit);

        connect(cancelButton, &ElaPushButton::clicked, this, &T_CreateNewReportWidget::slot_cancelButtonClicked);

        connect(confirmButton, &ElaPushButton::clicked, this, &T_CreateNewReportWidget::slot_confirmButtonClicked);

    }

    T_CreateNewReportWidget::~T_CreateNewReportWidget()
    {
    }

    void T_CreateNewReportWidget::slot_onNameEditTextEdit(const QString& nameText)
    {
        setErrorMessagePrompt(QStringLiteral("请输入"));
        m_reportName = nameText;
    }

    void T_CreateNewReportWidget::slot_cancelButtonClicked()
    {
        //关闭窗口
        ElaWidget::close();
    }

    void T_CreateNewReportWidget::slot_confirmButtonClicked()
    {
        auto _isLegal = GlobalHelperInstance->isLegalName(m_reportName);
        if (!_isLegal)
        {
            return;
        }
        else
        {
            GenerateReportBaseInstance->setCurrentReportName(m_reportName);
            //关闭窗口
            ElaWidget::close();
            GenerateReport::CreateNewReport tes;
            tes.accept();
        }
    }

    void T_CreateNewReportWidget::setErrorMessagePrompt(QString errorMessage)
    {
        _nameEdit->setPlaceholderText(errorMessage);
    }
}
